home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
C⁄C++
/
CModalProgress 1.1
/
Read Me
< prev
next >
Wrap
Text File
|
1995-02-18
|
9KB
|
229 lines
CModalProgress Read Me
-------------- -------
Version 1.1
18th of February 1995
© 1994, 1995 Alysoft Solutions. All rights reserved.
The accompanying source code is released as 'freeware'. And as such you
are free to use it in any way that you see fit. The only exception is
that you cannot sell for profit, the source on its own. It is ok to use
the source in other products which are then sold for profit. It is also
reasonable to charge a small amount for downloading from ftp sites etc.
or for the cost of media.
Items in this Archive
---------------------
Read Me - This file
CModalProgress.cp - The class source
CModalProgress.h - The classes header file
ProgressDialog.rsrc - The required resourcess for the class
CTestDialogs.cp - Example source code
CTestDialogs.h - Header file for examples
main.cp - Main application code for example
TestResources.rsrc - Resources for example
ProgressDialog - Example application. This is a 68K binary for running
on a 68k based machine or emulated on a PowerPC machine.
Description
----------
The CModalProgress class provides a standard interface for displaying a
Modal dialog during a time intensive task. The progress of the task can
be displayed in the dialog in one of three ways:
• Textual representation of the percent complete
• A progress bar growing to the right as the task progresses
• An infinite progress bar (as used by the Finders 'Find' command)
Dialog Creation
---------------
The visual appearance of the dialog used by the CModalProgress task is
generated in a standard DLOG and DITL resource. There are several
important items to note:
• Item 1 must be an OK equivalent button
• Item 2 must be a CANCEL equivalent button
• Item 3 must be a user item for the OK button outline
These items are required for standard keyboard mappings. ie. the OK
button will be activated when Enter or Return are pressed. The CANCEL
button will be activated when ESC or Command-. are pressed.
If this functionality is not required, the buttons should still be
created but they should be disabled and the hidden away from view.
If a progress bar or infinite progress bar are required, a user item
should be created for the bar to be drawn into. This item is then passed
to the SetProgressBar() or SetInfiniteBar() methods.
If a textual progress indicator is required, a static text item should
be generated for this purpose. The item number for this static text is
then passed to the SetPercentText() method along with the frequency at
which you want the number to be updated. eg every 1% every 5% every 20%
etc (would take values of 1, 5, 20 repectively). Make sure that this
item is Enabled. If it is not, it will not be used by the clase.
Setting of Param text fields (^0 ^1 ^2 ^3) located in the dialog can be
done in two ways. The easiest is to pass the strings to the SetupDialog()
method. The other method can be used when the class is overridden and the
SetParamText() method is used to set the strings when the standard
SetupDialog() method is called.
Class Use
---------
The progress class breaks the task into separate states each state taking
up a certain percentage of the total task time (except for the infinite
progress bar).
Each state contains a resolution or a state space that is set as the task
progresses. eg The Finder's Copy command whould have a read and then a
write state. The state space may correspond to the size of the file, the
copy command would increment the current state value each block that was
read and then written.
eg. The Finder Copy Command.
Copying one file that is 128k in size.
• Generate CModalProgress object
• Provide DLOG resource ID
• call SetProgressBar() with the user item of the progress bar
• call SetCurrentState(50), 50 being 50% of total tasks as the first
thing we will do is the reading which takes half of the time.
• call SetStateSpace(128), 128 is our state space. As we read in each
1k block of the file we will increment the state value, when it
reaches 128 we are done.
• call BeginModal(), start the ball rolling...Show the window.
• Do read processing, calling SetCurrentStateValue() each block we
read.
Repeat similar for the write processing
• call SetCurrentState(100), this state goes from 50 up to 100 %
• call SetStateSpace(128), representing the 128k of data
• Do the write processing.
• call EndModal()
• delete the CModalProgress object
The state space for the current state should be set to any value that is
directly related to the processing task. As in the above example, the
state space was set 128 as the data being read in was going to be 128k.
Or if you are processing a text file, the state space may be the number
of lines to process. Then each line that is processed, the modalprogress
object is notified and it updates the progress bar or text accordingly.
Event Handling
--------------
The CModalProgress class has two ways to handle application events. The
first and the simplest solution is to let the progress object handle all
events itself, throwing away any event that it does not use. This is
accomplished by calling the ProcessModal() method continualy during
the life of the task.
The second method is to pass the events into the progress object by calling
the CanProcessEvent() method. This method will use the event if it was
actually directed to the dialog and return a value of TRUE to the caller.
If it does not use the event, then it will return a value of FALSE. This
event can then be passed on to the applications main event loop to be
processed in the usual way.
If this second method is used, then there is another method which will need
to be called periodically if you are using the infinite bar version of
the dialog. The method ProcessIdle() gives the bar some time to draw
itself which was usually done from the ProcessModal() method. If there
is no infinite bar in the dialog (or you continue to use the ProcessModal()
method) then there is no need to call the ProcessIdle() method.
NOTE: By looking at the source you may think that the CanProcessEvent()
method already calls the ProcessIdle() method and so you don't need to.
The problem is that the CanProcessEvent() will only get called if you
have an event to pass it (unless you pass lots of null events to it) in
which case the infinite bar would only get drawn when an event is issued.
Text Substitution
-----------------
Text can be substitued into the dialog's static text items in two ways.
There are two versions of the SetupDialog() method, one of which takes
four Str255 parameters, these will be used to make a ParamText() call to
the toolbox before generating the new dialog.
The second way to set up static text items is to override the SetParamText()
method. This method is called by the standard SetupDialog() method before
it generates the new dialog. The default version of SetParamText() just
sets all strings to NULL, but by overriding it you can set the strings to
anything you want.
Other Information
-----------------
Forming part of this archive is a small application showing several
examples of how to use the CModalProgress class. The code for these
examples is included for further reference.
Registration
------------
As previously stated, this software is 'freeware'. However, if you wish
to register with me that you are using this package, I can forward any
modifications, bug fixes etc to you as soon as they are available.
Also, if you find any bugs in the code you can forward reports to me and
will eventually receive updates to fix the problems.
Any other form of criticism, suggestions etc will be most welcome.
Changes from Version 1.0
------------------------
There have been two bug fixes from version 1.0:
#1: The class now works correctly in Black and White.
#2: The class will now build and run on PowerMacs.
There have been several enhancements to the class:
#1: Setting of static text items using ParamText() toolbox routine.
#2: Event processing has been tidied up to provide more compatibility with
the appliactions main event loop.
NOTE: There should be no interface changes from the original Version 1.0
source. You should not need to modify any of your existing code which
used the version 1.0 source.
Acknowledments
--------------
Thanks must go to the following people for their help with this release:
Matthew Moss - For giving me HEAPS of help fixing the PowerMac problem.
David Plumpton - For helping to test the PowerMac changes.
Eric Kidd - For his list of changes and enhacments for the class
(sorry I couldn't include them all in this release!).
Other People: Robert Walker, Andy Hong, Aleksandar Totic.
Contact Address
---------------
Postal:
Alysoft Solutions
PO Box 387
Wollongong East
New South Wales 2520
Australia.
E-Mail:
heathcot@bnr.ca